package com.mydubbo.rpc.netty;

import org.jboss.netty.channel.ChannelHandlerContext;
import org.jboss.netty.channel.MessageEvent;
import org.jboss.netty.channel.SimpleChannelHandler;

import com.alibaba.fastjson.JSON;
import com.mydubbo.rpc.Rpc;
import com.mydubbo.rpc.dto.Response;
import com.mydubbo.util.Log;

public class NettyClientHandler extends SimpleChannelHandler {

	@Override
	public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception {
		super.messageReceived(ctx, e);
		Log.log("客户端接收到消息=>" + e.getMessage());
		Object result = e.getMessage();
		String resultJsonStr = result.toString();
		Response response = JSON.parseObject(resultJsonStr, Response.class);
		Rpc rpc = Rpc.getRpc(response.getId());
		rpc.setResponse(response);
	}


}
